package Question01;

public class main {
    public static void main(String[] args) {
        String str = "i very love xhl";
        System.out.println("原文本：===================");
        System.out.println(str);
        System.out.println("任务实现================");
        //单独取出来
        String[] str1 = str.split(" ");
        int cnt=0;
        for (String string : str1) {
            System.out.print(++cnt + string + " ");
        }
        System.out.println();
        //替换指定单词
        String str2 = str.replace("love","like");
        System.out.println(str2);
        //添加单词
        int index = str2.lastIndexOf("very");
        StringBuilder str3 = new StringBuilder(str2);
        str3.insert(index,"very ");
        System.out.println(str3);
        //把每个单词首字母大写
        String[] str4 = str3.toString().trim().split(" ");//重新拼接成字符串
        StringBuilder result = new StringBuilder();
        for (String s : str4) {
            result.append(s.substring(0,1).toUpperCase()).append(s.substring(1).toLowerCase()).append(" ");
        }
        System.out.println(result);
    }
}
